package web.java.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import web.java.service.impl.EmpServiceImpl;

public class LoginServlet extends HttpServlet {

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		EmpServiceImpl service=new EmpServiceImpl();
		boolean result=service.verify(username,password);
		if(result==true){
			//验证成功，创建session，并跳转到ListServlet
			HttpSession session=request.getSession();
			session.setAttribute("login",true);
			request.getRequestDispatcher("ListServlet").forward(request,response);
		}else{
			//验证失败，返回login.jsp页面
			response.sendRedirect(request.getContextPath()+"/login.jsp");
		}
	}

}
